pub mod error;
mod hash;
pub mod json;
pub mod ruma_wrapper;
pub mod string;
pub mod time;

pub(crate) use error::{Error, Result};
use rand::{self, thread_rng, Rng};

pub fn random_string(length: usize) -> String {
    thread_rng()
        .sample_iter(&rand::distributions::Alphanumeric)
        .take(length)
        .map(char::from)
        .collect()
}

#[must_use]
pub fn generate_keypair() -> Vec<u8> {
    let mut value = random_string(8).as_bytes().to_vec();
    value.push(0xFF);
    value.extend_from_slice(
        &ruma::signatures::Ed25519KeyPair::generate()
            .expect("Ed25519KeyPair generation always works (?)"),
    );
    value
}
